#include <iostream>
#include <mutex>
using namespace std;

// 懒汉模式单例类
template<typename T>
class Singleton{
	volatile static T* inst;  // 直接从内存中读取数据
	static std::mutex lock;   // 互斥锁
public:
	static T* getInstance(){
		if (inst == NULL){
			lock.lock();
			if (NULL == inst){
				inst = new T();
			}
			lock.unlock();
		}
		return inst;
	}
};